/*
    Heart of Gold engine management system
    Copyright (C) 2004 Heart of Gold development team

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package com.heartOfGold.view;

/*
 *  The Master Page tender for the Megasquirt HOG_Component
 *  @author Ryan Higgins
 *  @date May 2004
 */

import java.awt.CardLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JPanel;
import javax.swing.JOptionPane;

import com.heartOfGold.controller.Fuel;

import java.util.Vector;

public class FuelMaster extends JPanel implements ActionListener {

    private Vector<Object> cards = new Vector<Object>();
    // widgets

    private CardLayout layout;
    private FuelTable table;
    private FuelEngine engine;
    private FuelRunTime runTime;
    private FuelEnrichment enrichment;

    public FuelMaster(final Fuel m) {
        layout = new CardLayout();
        setLayout(layout);

        // setup the table page
        table = new FuelTable(this, m);
        add("Fuel Mixture Table", table);
        cards.add("Fuel Mixture Table");

        // setup the engine page
        engine = new FuelEngine(this, m);
        add("Engine and Injector Setup", engine);
        cards.add("Engine and Injector Setup");

        // setup the run time page
        runTime = new FuelRunTime(this, m);
        add("Digital Dashboard", runTime);
        cards.add("Digital Dashboard");

        // setup the enrichment setup page
        enrichment = new FuelEnrichment(this, m);
        add("Enrichment Setup", enrichment);
        cards.add("Enrichment Setup");

        // setup the main fuel menu
        add("Main", new FuelMain(this));
        cards.add("Main");

        layout.show(this, "Main");
    }

    public final boolean switchScreen(final String screen) {
        if (!cards.contains(screen)) {
            return false;
        }
        layout.show(this, screen);
        return true;
    }

    public final void actionPerformed(final ActionEvent ae) {
        String command = ae.getActionCommand();
        if (!switchScreen(command)) {
            JOptionPane.showMessageDialog(this,
                    "This function is not yet implemented", "Not Implemented",
                    JOptionPane.INFORMATION_MESSAGE);
            return;
        }
    }

    public final void update(final char lastCommand, final int[] constants) {
        if (lastCommand == 'V') {
            table.update(constants);
            engine.update(constants);
            enrichment.update(constants);
            return;
        }
        if (lastCommand == 'A') {
            runTime.update(constants);
            return;
        }
    }
}
